<?php

class Theme
{
	function getSiteTheme($id)
	{
		if($id > 0)
		{
			$select = 'SELECT * FROM '.DB_PERFIX.'themes WHERE id='.$id.' LIMIT 1;';
			$result = mysql_query($select);
			if($result)
			{
				while($row = mysql_fetch_array($result))
				{
					
					$item['id']					= $row['id'];
					$item['title'] 				= $row['title'];
					$item['site_id']			= $row['site_id'];
					$item['site_default'] 		= $row['site_default'];
					
					$item['theme_type']			= $row['theme_type'];
					$item['fixed_width']		= $row['fixed_width'];
					$item['horisontal_pos']		= $row['horisontal_pos'];
					
					$item['border_site']		= $row['border_site'];
					$item['border_content'] 	= $row['border_content'];
					
					$item['header']				= $row['header']; 
					$item['header_fixed']		= $row['header_fixed']; 
					$item['header_border'] 		= $row['header_border'];
					$item['header_hfb'] 		= $row['header_hfb'];
					$item['header_content'] 	= $row['header_content'];
					
					$item['footer']				= $row['footer'];
					$item['footer_fixed'] 		= $row['footer_fixed'];
					$item['footer_border'] 		= $row['footer_border'];
					$item['footer_hfb'] 		= $row['footer_hfb'];
					$item['footer_content'] 	= $row['footer_content'];
					
					$item['col_left']			= $row['col_left'];
					$item['col_left_border'] 	= $row['col_left_border'];
					$item['col_left_hfb'] 		= $row['col_left_hfb'];
					$item['col_left_content'] 	= $row['col_left_content'];
					
					$item['col_right']			= $row['col_right'];
					$item['col_right_border'] 	= $row['col_right_border'];
					$item['col_right_hfb'] 		= $row['col_right_hfb'];
					$item['col_right_content'] 	= $row['col_right_content'];
					
					$item['hfb_set'] 			= $row['hfb_set'];
					$item['hfb_com_set'] 		= $row['hfb_com_set'];
					
				}
				return $item;
			}
		}
	}
}
	
	function getIsSelectedHTML($val='', $val2='')
	{
		if($val == $val2)
		{ return ' selected="selected" '; }
	}
	
	function getIsEnabledHTML($val)
	{
		if($val == false)
		{ return ' disabled="disabled" '; }
	}
	
	function getIsDisabledHTML($val)
	{
		if($val == false)
		{ return ' disabled="disabled" '; }
	}
	
	function getBorder($id)
	{
		if($id > 0)
		{
			$select = 'SELECT * FROM '.DB_PERFIX.'com_borders WHERE id= '.$id.' LIMIT 1;';
			$result = mysql_query($select);
			while($row = mysql_fetch_array($result))
			{
				$item['id'] = $row['id'];
				$item['type'] = $row['type'];
				$item['name'] = $row['name'];
				$item['width'] = $row['width'];
				$item['image_bg'] = $row['image_bg'];
				$item['image_top'] = $row['image_top'];
				$item['image_top_l'] = $row['image_top_l'];
				$item['image_top_r'] = $row['image_top_r'];
				$item['image_bot'] = $row['image_bot'];
				$item['image_bot_l'] = $row['image_bot_l'];
				$item['image_bot_r'] = $row['image_bot_r'];
				$item['image_mid_l'] = $row['image_mid_l'];
				$item['image_mid_r'] = $row['image_mid_r'];
			}
			return $item;
		}
	}
	
	function getBorderHTML($border, $tbt='top', $id=0)
	{
		if(($border == '') && ($id > 0))
		{ $border = getBorder($id); }
		if($border)
		{
			$out = '';
			if($tbt == 'top')
			{
				$out = 	'<div class="rc_border">';
				$out .= 	'<div class="border_'.$border['id'].'">';
				if($border['type'] > 0)
				{ 
					
					if($border['type'] > 1)
					{
						if($border['image_top_l'] != '')
						{ $out .= 			'<div class="tl_'.$border['id'].'">'; }
							if($border['image_top_r'] != '')
							{ $out .= 			'<div class="tr_'.$border['id'].'">'; }
					}
					$out .= '<div class="top_'.$border['id'].'"></div>';
					if($border['type'] > 1)
					{
							if($border['image_top_r'] != '')
							{ $out .= 			'</div>'; }
						if($border['image_top_l'] != '')
						{ $out .= 			'</div>'; }
					}
					$out .= 		'<div class="mid_l_'.$border['id'].'">';
						$out .= 		'<div class="mid_r_'.$border['id'].'">';
							$out .= 		'<div class="core_'.$border['id'].'">';
				}
			}
			else
			{
				if($border['type'] > 0)
				{ 
					$out .= 				'</div>';
					$out .= 			'</div>';
					$out .= 		'</div>';
					if($border['type'] > 1)
					{
						if($border['image_bot_l'] != '')
						{ $out .= 			'<div class="bl_'.$border['id'].'">'; }
							if($border['image_bot_r'] != '')
							{ $out .= 			'<div class="br_'.$border['id'].'">'; }
					}
					$out .= '<div class="bot_'.$border['id'].'"></div>';
					if($border['type'] > 1)
					{
							if($border['image_bot_r'] != '')
							{ $out .= 			'</div>'; }
						if($border['image_bot_l'] != '')
						{ $out .= 			'</div>'; }
					}
				}
				$out .= 	'</div>';
				$out .= '</div>';
			}
			return $out;
		}
	}
	
	function getHeader($id)
	{
		if($id > 0)
		{
			$select = 'SELECT * FROM '.DB_PERFIX.'com_headers WHERE id='.$id.' LIMIT 1;';
			$result = mysql_query($select);
			while($row = mysql_fetch_array($result))
			{
				$item['id'] = $row['id'];
				$item['name'] = $row['name'];
				$item['l_image'] = $row['l_image'];
				$item['image'] = $row['image'];
				$item['image2'] = $row['image2'];
				$item['r_image'] = $row['r_image'];
				$item['height'] = $row['height'];
				$item['button'] = $row['button'];
				$item['icon'] = $row['icon'];
				$item['imagefont'] = $row['imagefont'];
				$item['active'] = $row['active'];
			}
			return $item;
			
		}
	}
	
	function getHeaderHTML($id, $buttons, $text, $text2='', $text3='', $icon='')
	{
		$header = '';
		if($id > 0)
		{
			if($headers)
			{
				foreach($headers as $item)
				{
					if($item['id'] == $id)
					{ $header = $item; }
				}
			}
			
			if(!$header)
			{ $header = getHeader($id); }
			if($header)
			{
				$out = '<div class="com_header">';
					$out .= '<div class="ch_'.$id.'">';
						if($header['l_image'] != '')
						{ $out .= '<div class="ch_left">'; }
							if($header['r_image'] != '')
							{ $out .= '<div class="ch_right">'; }
								$out .= '<div class="ch_center">';
									$out .= '<div class="ch_content">';
										if($header['icon'] > 0)
										{ 
											$iconset = getIconSet($header['icon']); 
											if($iconset)
											{
												$out .= '<span class="ch_icon"><img src="images/system/icon_spacer.gif"';
												$out .= ' alt="" style="width:'.$iconset['width'].'px; height:'.$iconset['height'].'px;" /></span>';
											}
										}
										
										if($header['imagefont'] == 1)
										{ 
											$out .= '<h2 class="ch_txt">';
											$out .= getImageFont($text, $text2, '', '', 0, 0); 
											$out .= '</h2>';
										}
										else
										{ 
											$out .= '<h2 class="ch_txt">';
											$out .= $text; 
											$out .= '</h2>';
											$out .= '<h2 class="ch_txt2">'.$text2.'</h2>';
											$out .= '<h2 class="ch_txt3">'.$text3.'</h2>';
										}
										if($buttons != '')
										{ $out .= '<span class="ch_buttons">'.getButtonsHTML($header['button'], $buttons).'</span>'; }
									$out .= '</div>';
								$out .= '</div>';
							if($header['r_image'] != '')
							{ $out .= '</div>'; }
						if($header['l_image'] != '')
						{ $out .= '</div>'; }
					$out .= '</div>';
				$out .= '</div>';
				return $out;
			}
		}
	}
	
	function getFooter($id)
	{
		if($id > 0)
		{
			$select = 'SELECT * FROM '.DB_PERFIX.'com_footers WHERE id='.$id.' LIMIT 1;';
			$result = mysql_query($select);
			while($row = mysql_fetch_array($result))
			{
				$item['id'] = $row['id'];
				$item['name'] = $row['name'];
				$item['l_image'] = $row['l_image'];
				$item['image'] = $row['image'];
				$item['image2'] = $row['image2'];
				$item['r_image'] = $row['r_image'];
				$item['height'] = $row['height'];
				$item['button'] = $row['button'];
				$item['icon'] = $row['icon'];
				$item['imagefont'] = $row['imagefont'];
				$item['active'] = $row['active'];
			}
			return $item;
		}
	}
	
	function getFooterHTML($id, $buttons, $text, $text2='', $text3='', $icon='')
	{
		$footer = '';
		if($id > 0)
		{
			if($footers)
			{
				foreach($footers as $item)
				{
					if($item['id'] == $id)
					{ $footer = $item; }
				}
			}
			
			if(!$footer)
			{ $footer = getFooter($id); }
			if($footer)
			{
				$out = '<div class="com_footer">';
					$out .= '<div class="cf_'.$id.'">';
						if($footer['l_image'] != '')
						{ $out .= '<div class="cf_left">'; }
							if($footer['r_image'] != '')
							{ $out .= '<div class="cf_right">'; }
								$out .= '<div class="cf_center">';
									$out .= '<div class="cf_content">';
										if($footer['icon'] > 0)
										{ 
											$iconset = getIconSet($footer['icon']); 
											if($iconset)
											{
												$out .= '<span class="cf_icon"><img src="images/system/icon_spacer.gif"';
												$out .= ' alt="" style="width:'.$iconset['width'].'px; height:'.$iconset['height'].'px;" /></span>';
											}
										}
										$out .= '<h2 class="cf_txt">';
										if($footer['imagefont'] == 1)
										{ getImageFont($text, $text2, '', '', 0, 0); }
										else
										{ $out .= $text; }
										$out .= '</h2>';
										$out .= '<h2 class="cf_txt2">'.$text2.'</h2>';
										$out .= '<h2 class="cf_txt3">'.$text3.'</h2>';
										if($buttons != '')
										{ $out .= '<span class="cf_buttons">'.getButtonsHTML($footer['button'], $buttons).'</span>'; }
									$out .= '</div>';
								$out .= '</div>';
							if($footer['r_image'] != '')
							{ $out .= '</div>'; }
						if($footer['l_image'] != '')
						{ $out .= '</div>'; }
					$out .= '</div>';
				$out .= '</div>';
				return $out;
			}
		}
	}
	
	function getMenuArray($startid, $level=0)
	{
		if($startid > 0)
		{
			$i=0;
			$result = mysql_query('SELECT * FROM '.DB_PERFIX.'sitemap_pages WHERE parent_id='.$startid.' AND active=1 ORDER BY menu_order ASC;');
			while($row = mysql_fetch_array($result))
			{
				$item[$i]['id'] 		= $row['id'];
				$item[$i]['parent_id'] 	= $row['parent_id'];
				$item[$i]['site_id'] 	= $row['site_id'];
				$item[$i]['title']	 	= $row['title'];
				$item[$i]['link_type'] 	= $row['link_type'];
				$item[$i]['link_id'] 	= $row['link_id'];
				$item[$i]['link_url']	= $row['link_url'];
				$item[$i]['active'] 	= $row['active'];
				$item[$i]['access'] 	= $row['access'];
				$item[$i]['level'] 		= $level;
				$item[$i]['subitems'] 	= getMenuArray($item[$i]['id'], ($level+1));
				$i++;
			}
			return $item;
		}
	}
	
	function getMenuLiItems($startid, $html='')
	{
		$items = getMenuArray($startid);
		$i=0;
		if($items)
		{
			foreach($items as $item)
			{
				$class = 'level_'.$item['level'];
				if(count($items) == ($i+1))
				{ $class .= ' last '; }
				if($i == 0)
				{ $class .= ' first '; }
				$target = '';
				if($item['link_type'] == 2)
				{ $target = 'target="_blank"'; }
				
				if($item['link_type'] == 5)
				{ 
					$item['link_url'] = '?m='.$item['id']; 
					if($_REQUEST['m'] == $item['id'])
					{ $class .= ' active '; }
				}
				$html .= '<li class="'.$class.'">';
				$html .= 	'<a class="'.$class.'" href="'.$item['link_url'].'" '.$target.'>';
				$html .= 		'<h2>';
				$html .= 			'<span>';
				$html .= 				'<div>';
				$html .=					$item['title'];
				$html .= 				'</div>';
				$html .= 			'</span>';
				$html .= 		'</h2>';
				$html .= 	'</a>';
				$html .= '</li>';
				$i++;
			}
		}
		return $html;
	}
	
	function getMenuLevel($startid, $level=0)
	{
		
	}
	
	function getButtonsHTML($id, $params, $nowrap=0)
	{	
		$out = '';
		if($params)
		{
			$jQuery = 0;
			$buttontag = 0;
			if($params['type'] > 0)
			{ $type = $params['type']; }
			global $theme;
			if(is_object($theme))
			{
				$button = $theme->getButton($id);
				$type = $button['type'];
			}
			if($nowrap == 0)
			{ $out  = getButtonWrapTop($id); }
			foreach($params as $param)
			{ $out .= getButtonHTML($param['title'], $param['href'], $param['onclick'], $param['params'], $type); } 
			if($nowrap == 0)
			{ $out .= getButtonWrapBot($id); }
		}
		return $out;
	}
	
	function getButtonHTML($text, $href, $onclick, $params, $type = 0)
	{
		$todo = '';
		$icon = '';
		$iconR = '';
		$tagBtn = 'button';
		$tagA 	= 'a';
				
		if($href != '')
		{ $todo .= ' href="'.$href.'" '; }
		if($onclick != '')
		{ $todo .= ' onclick="'.$onclick.'" '; }
		
		if(!$params['class'])
		{ $params['class'] = 'btn btn-default'; }
		
		if($params)
		{
			$keys = array_keys($params);
			foreach($keys as $key)
			{ 
				switch($key)
				{
					case 'icon':
						$icon = '<i class="'.$params[$key].'"></i>&nbsp;&nbsp;';
					break;
					case 'iconR':
						$iconR = '<i class="'.$params[$key].'"></i>&nbsp;&nbsp;';
					break;
					default:
						$todo .= $key.'="'.$params[$key].'" '; 
					break;
				}
				
			}
			if($params['tag'] != '')
			{
				$tagBtn = $params['tag'];
				$tagA = $params['tag'];
			}
		}
		
		if($todo != '')
		{ 
			global $theme;
			if($theme->getBootstrap() > 0)
			{ 
				switch($type)
				{
					case 2:
						$out  = '<'.$tagBtn.' '.$todo.'>'.$icon.$text.$iconR.'</'.$tagBtn.'>';
					break;
					
					default:
						$out  = '<'.$tagA.' '.$todo.'>'.$icon.$text.$iconR.'</'.$tagA.'>';
					break;
				}
				
			}
			else
			{
				if($type > 0)
				{ 
					if($type == 1)
					{ 
						$out  = '<li class="com_button button"><'.$tagA.' '.$todo.'>'.$text.'</'.$tagA.'></li>';
						$out .= '<li class="com_button"><'.$tagA.' class="spacer">&nbsp;&nbsp;</'.$tagA.'></li>';
					}
					if($type == 2)
					{ 
						$out  = '<li class="com_button button"><'.$tagBtn.' '.$todo.'><span class="button-content">'.$text.'</span></'.$tagBtn.'></li>';
						$out .= '<li class="com_button"><a class="spacer">&nbsp;&nbsp;</a></li>';
					}
				}
				else
				{ $out  = '<li class="com_button"><'.$tagA.' '.$todo.'><span class="right"><span><span class="center">'.$text.'&nbsp;</span></span></span></'.$tagA.'></li>'; }
			}
			return $out; 
		}
	}
	
	function getButtonWrapTop($id)
	{ 
		global $theme;
		if($theme->getBootstrap() > 0)
		{ return '<div class="btn-group">'; }
		else
		{ return '<div class="com_buttons"><div class="cb_'.$id.'"><ul>'; }
	}
	
	function getButtonWrapBot($id)
	{ 
		global $theme;
		if($theme->getBootstrap() > 0)
		{ return '</div>'; }
		else
		{ return '</ul></div></div>'; }
	}
	
	function getComponent($id, $trigger='')
	{
		$result = mysql_query("SELECT * FROM ".DB_PERFIX."components WHERE id=".$id." AND active=1;");
		while($row = mysql_fetch_array($result))
		{
			$component['id'] = $row['id'];
			$component['name_l'] = $row['name_l'];
			$component['name_r'] = $row['name_r'];
			$component['icon'] = $row['icon'];
			$component['path'] = $row['path'];
			$component['hfb_set'] = $row['hfb_set'];
			$component['site_template'] = $row['site_template'];
			$component['active'] = $row['active'];
		}
		return $component;
	}
	
	
	function getButton($type, $text = 'button', $link = '', $action = '', $submit = '', $other = '', $id = '', $table='1')
	{
		$content = "";
		$result = mysql_query("SELECT * FROM ".DB_PERFIX."buttons WHERE id=".$type." AND active=1;");
		while($row = mysql_fetch_array($result))
		{
			$item['id'] = $row['id'];
			$item['name'] = $row['name'];
			$item['l_image'] = $row['l_image'];
			$item['image'] = $row['image'];
			$item['r_image'] = $row['r_image'];
			$item['height'] = $row['height'];
			$item['style'] = $row['style'];
			if($item['l_image'] != "")
			{
				$content = $content.'<td valign="bottom" align="right" height="'.$item['height'].'"><img src="'.BUTTONS_URL.$item['l_image'].'" alt="#" border="0" /></td>';
			}
			if($item['image'] != "")
			{
				$content = $content.'<td nowrap valign="middle" class="button_type_'.$item['id'].'_txt" style="background-image: url('.BUTTONS_URL.$item['image'].'); background-repeat: repeat-x; background-position: bottom; '.$item['style'].'">';
				if($action != '')
				{
					$content = $content.'<a class="button_type_'.$item['id'].'_lnk" onclick="'.$action.'">'.$text.'</a></td>';
				}
				else
				{
					if($submit != '')
					{
						if($id != '')
						{
							$id = 'id="'.$id.'"';
						}
						$content = $content.'<input '.$id.' type="'.$submit.'" class="button_type_'.$item['id'].'_txt" value="'.$text.'" style="height:'.$item['height'].'px; border:0px; padding:0px; margin:0px; align:right; background-color: transparent; '.$item['style'].'" '.$other.' /></td>';
					}
					else
					{
						$content = $content.'<a class="button_type_'.$item['id'].'_lnk" href="'.$link.'">'.$text.'</a></td>';
					}
				}
			}
			if($item['r_image'] != "")
			{
				$content = $content.'<td valign="bottom"  align="left" height="'.$item['height'].'"><img src="'.BUTTONS_URL.$item['r_image'].'" alt="#" border="0" /></td>';
			}
		}
		if($table == '1')
		{
			if(($id != '') && ($submit != ''))
			{
				$id = 'id="'.$id.'"';
			}
			$output = '<table '.$id.' cellpadding="0" cellspacing="0" border="0" style="margin-left:4px; display:inline;">'."\n";
			$output = $output. '<tr>'."\n";
		}
		$output = $output.$content;
		if($table == '1')
		{
			$output = $output. '</tr>'."\n";
			$output = $output. '</table>'."\n";
		}
		return $output;
	}
	
	
	function getModTemplate($id)
	{
		$select = 'SELECT * FROM '.DB_PERFIX.'modules WHERE mod_id='.$id.' AND site_id='.SITE_ID.' AND active=1 LIMIT 1;';
		$result = mysql_query($select);
		while($row = mysql_fetch_array($result))
		{
			$item['id'] = $row['id'];
			$item['set_id'] = $row['set_id'];
			$item['site_id'] = $row['site_id'];
			$item['mod_id'] = $row['mod_id'];
			$item['name_l'] = $row['name_l'];
			$item['name_r'] = $row['name_r'];
			$item['icon'] = $row['icon'];
			$item['type'] = $row['type'];
			$item['path'] = $row['path'];
			$item['hfb_set'] = $row['hfb_set'];
			$item['active'] = $row['active'];
			$item['max'] = $row['max'];
			$item['cols'] = $row['cols'];
			$item['rows'] = $row['rows'];
			$item['indexing'] = $row['indexing'];
		}
		if($item['icon'] > 0)
		{
			$select = 'SELECT set_id, image, style FROM '.DB_PERFIX.'icons WHERE id='.$module['icon'].' LIMIT 1;';
			$result = mysql_query($select);
			while($row = mysql_fetch_array($result))
			{
				$item['icon_set'] 	= $row['set_id'];
				$item['icon_image'] 	= $row['image'];
				$item['icon_style'] 	= $row['style'];
			}
		}
		return $item;
	}
	
	function getIcon($icon_set, $icon_image, $style="")
	{ return '<img src="'.ICONS_URL.$icon_set.'/'.$icon_image.'" border="0" style="'.$style.'" />'; }
	
	function getModPath($id)
	{
		$select = 'SELECT path FROM '.DB_PERFIX.'modules WHERE id='.$id.' AND active=1;';
		$result = mysql_query($select);
		while($row = mysql_fetch_array($result))
		{ $module['path'] = $row['path']; }
		return $module['path'];
	}
	
	function getContentImage($id)
	{
		$select = 'SELECT name, image, style, type, url FROM '.DB_PERFIX.'template_images WHERE id='.$id.' AND active=1 LIMIT 1;';
		$result = mysql_query($select);
		while($row = mysql_fetch_array($result))
		{
			$item['name'] = $row['name'];
			$item['image'] = $row['image'];
			$item['style'] = $row['style'];
			$item['type'] = $row['type'];
			$item['url'] = $row['url'];
		}
		
		$output = '<table width="100%" style="'.$item['style'].'" cellpadding="0" cellspacing="0" border="0">';
		$output = $output.'<tr>';
		$output = $output.'<td align="center">';
		if($item['type'] == 1)
		{ $output = $output.'<a href="'.$item['url'].'"><img alt="'.$item['name'].'" src="'.HTML_IMAGE_URL.$item['image'].'" border=0 /></a>'; }
		$output = $output.'</td>';
		$output = $output.'</tr>';
		$output = $output.'</table>';
		return $output;
	}
	
	function getWrapStyleTop($style)
	{
		$wrap  ='<table width="100%" cellpadding="0" cellspacing="0" border="0">';
		$wrap .='<tr>';
		$wrap .='<td style="'.$style.'">';
		
		return $wrap;
	}
	
	function getWrapTop($id)
	{
		$wrap  ='<table class="container_type_'.$id.'_table" width="100%" cellpadding="0" cellspacing="0" border="0">';
		$wrap .='<tr>';
		$wrap .='<td class="container_type_'.$id.'_td">';
		
		return $wrap;
	}
	
	function getWrapMidTop($id)
	{
		$wrap  ='<table class="container_type_'.$id.'_table_mid" width="100%" cellpadding="0" cellspacing="0" border="0">';
		$wrap .='<tr>';
		$wrap .='<td class="container_type_'.$id.'_td_mid">';
		
		return $wrap;
	}
	
	function getWrapBot($id)
	{
		$wrap  ='</td>';
		$wrap .='</tr>';
		$wrap .='</table>';
		return $wrap;
	}
	
	function getComTemplate($comId)
	{
		$select = 'SELECT id, name_l, name_r, hfb_set, icon, site_template FROM '.DB_PERFIX.'components WHERE id='.$comId.' AND active=1;';
		$result = mysql_query($select);
		while($row = mysql_fetch_array($result))
		{
			$com['id'] = $row['id'];
			$com['name_l'] = $row['name_l'];
			$com['name_r'] = $row['name_r'];
			$com['hfb_set'] = $row['hfb_set'];
			$com['icon'] = $row['icon'];
			$com['site_template'] = $row['site_template'];
			if($row['hfb_set'] > 0)
			{ $hfb = $row['hfb_set']; }
			else
			{ $hfb = DEF_HFB; }
		}
		if($com['icon'] > 0)
		{
			$select = 'SELECT set_id, image, style FROM '.DB_PERFIX.'icons WHERE id='.$com['icon'].' LIMIT 1;';
			$result = mysql_query($select);
			while($row = mysql_fetch_array($result))
			{
				$com['icon_set'] 	= $row['set_id'];
				$com['icon_image'] 	= $row['image'];
				$com['icon_style'] 	= $row['style'];
			}
		}
		$select = 'SELECT id, header, footer, border, border2, button, h_button, f_button, wrap_style, content_style FROM '.DB_PERFIX.'hfb_sets WHERE id='.$hfb.';';
		$result = mysql_query($select);
		while($row = mysql_fetch_array($result))
		{
			$com['wrap'] = $row['id'];
			$com['header'] = $row['header'];
			$com['footer'] = $row['footer'];
			$com['border'] = $row['border'];
			$com['border2'] = $row['border2'];
			$com['button'] = $row['button'];
			$com['h_button'] = $row['h_button'];
			$com['f_button'] = $row['f_button'];
			$com['wrap_style'] = $row['wrap_style'];
			$com['content_style'] = $row['content_style'];
		}
		return $com;
	}
	
	
	function buildMenu($id, $type)
	{
		$output = "";
		$result = mysql_query('SELECT * FROM '.DB_PERFIX.'menu_templates WHERE template_id='.$id.' AND level=0 LIMIT 1;');
		while($row = mysql_fetch_array($result))
		{ 
			$output = '<div class="menu_'.$id.'" style="'.$row['style'].'"  >';
			if($row['image_l'] != '')
			{
				$output = $output.'<img src="'.MENU_PATH.$row['image_l'].'" border="0"></td>';
			}
			$lev2 = mysql_query('SELECT * FROM '.DB_PERFIX.'menu_templates WHERE template_id='.$id.' AND level=1 LIMIT 1;');
			while($level2 = mysql_fetch_array($lev2))
			{
				$output = $output.'<table width="100%" cellpadding="0" cellspacing="0" border="0" style="'.$level2['style'].'">';
				$output = $output.'<tr>';
				
				for($i = 0; $i<6; $i++)
				{
					$width=(100/6);
					if($i == 5)
					{	
						$class=2;
					}
					else
					{
						if($i < 1)
						{ $class=0; }
						else
						{ $class=1; }
					}
					if($level2['image_l'] != '')
					{
						$output = $output.'<td width="0" height="'.$level2['height'].'"><img src="../images/templates/menu/'.$level2['image_l'].'" border="0"></td>';
					}
					if($i==2)
					{
						$output = $output.'<td 	height="'.$level2['height'].'" 
												onMouseOver="this.style.backgroundImage=\'url(../images/templates/menu/'.$level2['image_hov'].')\'; 
															 this.className=\'menu_type_'.$row['template_id'].'_1_'.$class.'_hov\';" 
												onMouseOut="this.style.backgroundImage=\'url(../images/templates/menu/'.$level2['image_act'].')\'; 
															this.className=\'menu_type_'.$row['template_id'].'_1_'.$class.'_act\';" 
												align="center" 
												width="'.$width.'%" 
												class="menu_type_'.$row['template_id'].'_1_'.$class.'_act" 
												style="background-image: url(../images/templates/menu/'.$level2['image_act'].'); 
												background-repeat: repeat-x; cursor: pointer;">';
						$active= 'active ';
					}
					else
					{	
						$output = $output.'<td 	height="'.$level2['height'].'" 
												onMouseOver="this.style.backgroundImage=\'url(../images/templates/menu/'.$level2['image_hov'].')\'; 
															 this.className=\'menu_type_'.$row['template_id'].'_1_'.$class.'_hov\';" 
												onMouseOut="this.style.backgroundImage=\'url(../images/templates/menu/'.$level2['image_bg'].')\'; 
															this.className=\'menu_type_'.$row['template_id'].'_1_'.$class.'\';" 
												align="center" 
												width="'.$width.'%" 
												class="menu_type_'.$row['template_id'].'_1_'.$class.'" 
												style="background-image: url(../images/templates/menu/'.$level2['image_bg'].'); 
												background-repeat: repeat-x; cursor: pointer;">';
						$active= '';
					}
					$output = $output.'Link '.$active.$i;
					$output = $output.'</td>';
					if($level2['image_r'] != '')
					{
						$output = $output.'<td width="0" height="'.$level2['height'].'"><img src="../images/templates/menu/'.$level2['image_r'].'" border="0"></td>';
					}
				}
				
				$output = $output.'</tr>';
				$output = $output.'</table>';
			}
			if($row['image_r'] != '')
			{
				$output = $output.'<img class="right" src="'.MENU_PATH.$row['image_r'].'" border="0">';
			}
		}
		$output = $output.'</div>';
		return $output;
	}
	
	function getContentHtml($id)
	{
		$result = mysql_query('SELECT * FROM '.DB_PERFIX.'template_html WHERE id='.$id.' LIMIT 1;');
		while($row = mysql_fetch_array($result))
		{
			$item['html'] = $row['html'];
		}
		return $item['html'];
	}
?>